package Swing;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;

public class JButton_Demo extends JFrame {
    public JButton_Demo() throws IOException {
        Container contentPane = this.getContentPane();
        //将一个图片变成图标
//        URL resource =  JButton_Demo.class.getResource("jetbrains://idea/navigate/reference?project=untitled&path=1.PNG");

        ImageIcon imageIcon = new ImageIcon(ImageIO.read(new File("src/1.PNG")));

        //把图标放在按钮上
        JButton button = new JButton();
        button.setIcon(imageIcon);
        button.setToolTipText("图片按钮");//设置提示语

        contentPane.add(button);
        this.setVisible(true);
        this.setSize(500,500);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) throws IOException {
        new JButton_Demo();
    }
}
